//
//  DigitNoteSearchResultViewController.m
//  NewApp
//
//  Created by  on 12-7-8.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "DigitNoteSearchResultViewController.h"

@interface DigitNoteSearchResultViewController ()

@end

@implementation DigitNoteSearchResultViewController
@synthesize ID,keyword;

- (id) initWithID:(NSString *) aid keyword:(NSString *) aKeyword {
    if (self = [super init]) {
        self.ID = aid;
        self.keyword = aKeyword;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
	
}

- (void) dealloc {
    [ID release];
    [keyword release];
    [super dealloc];
}

- (void) loadRequest {
    [self.engine digitNoteDetailsWithCategoryID:self.ID keyword:self.keyword page:1];
}

- (void) requestDidFinished:(RequestEngine *)reqEngine withObject:(id)object {
    
    [self.datasourceObjects removeAllObjects];
    [self.tableView reloadData];
    
    UILabel *lbl = (UILabel *)[self.view viewWithTag:100];
    if (lbl) 
        [lbl removeFromSuperview];
    
    [super requestDidFinished:reqEngine withObject:object];
    
    if (self.datasourceObjects.count == 0) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.f, self.view.center.y - 20.f, 320.f, 40.f)];
        label.text = @"無搜尋結果";
        label.alpha = 0.7;
        label.tag = 100;
        label.backgroundColor = [UIColor clearColor];
        label.textAlignment = UITextAlignmentCenter;
        [self.view addSubview:label];
        [label release];
    }
}

- (void) searchButtonDidPressed {
    if (_searchBar.keywordTextfield.text.length == 0) 
        return;
    
    [self.engine digitNoteDetailsWithCategoryID:self.ID keyword:_searchBar.keywordTextfield.text page:1];
}


@end
